package cn.tedu.luban.account.main.rpc;

import cn.tedu.luban.account.api.AccountApi;
import cn.tedu.luban.account.main.converter.AccountConverter;
import cn.tedu.luban.account.main.service.AccountService;
import cn.tedu.luban.account.protocol.bo.AccountBO;
import cn.tedu.luban.account.protocol.dto.AccountDTO;
import cn.tedu.luban.account.protocol.param.AccountCreateParam;
import cn.tedu.luban.account.protocol.param.AccountPayParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AccountApiImpl implements AccountApi {

    @Autowired
    private AccountService accountService;

    @Autowired
    private AccountConverter accountConverter;

    @Override
    public Long createAccount(AccountCreateParam accountCreateParam) {
        try {
            Long accountId=accountService.createAccount(accountCreateParam);
            return accountId;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0L;
    }

    @Override
    public AccountDTO getAccount(Long userId) {
        try{
            AccountBO accountBO=accountService.getAccount(userId);
            return accountConverter.bo2dto(accountBO);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Long mockPayment(AccountPayParam param) {

        try {
            return accountService.mockPayment(param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0l;
    }
}
